package com.bianguo.android.pigeondemo.model;

import com.bianguo.android.pigeondemo.entity.MovieEntity;
import com.bianguo.android.pigeondemo.retrofit.BaseSubscriber;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.rx_cache2.DynamicKey;
import io.rx_cache2.EvictDynamicKey;

/**
 * Created by Administrator on 2018/6/4.
 */

public class MainModel extends BaseModel {

    public Disposable getMoviesList(int page, Consumer<MovieEntity> observer, Consumer<Throwable> onError) {
        Observable<MovieEntity> movieObservable = mModelFactory.apiCache.getMoviesList(mModelFactory.apiService.getMoviesList(page), new DynamicKey(page), new EvictDynamicKey(false));
        return doSubscribe(movieObservable, observer, onError);
    }

    public void getMoviesList(int page, BaseSubscriber<MovieEntity> subscriber) {
        Observable<MovieEntity> movieObservable = mModelFactory.apiCache.getMoviesList(mModelFactory.apiService.getMoviesList(page), new DynamicKey(page), new EvictDynamicKey(false));
        doSubscribe(movieObservable, subscriber);
    }
}
